package combinations.hierarchical;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

import com.sun.org.apache.bcel.internal.generic.NEW;

import combinations.Combinations;

import attributes.HierarchicalAttributes;

import trees.AttributeNode;
import utils.Util;


//algorithm details:
//the children are always to the left of the parent
public class HierarchicalCombinationsGenerator implements Combinations{

	//the trees  of attributes
	private HashMap<Integer, AttributeNode> trees;
	private HierarchicalAttributes hierarchicalAttributes;
	private int numRoots = 0;
	//used to find the index of a tree given its AttributeNode
	private HashMap<AttributeNode, Integer> treeIndexMap = new HashMap<AttributeNode, Integer>();
	
	public HierarchicalCombinationsGenerator(HierarchicalAttributes hierarchicalAttributes){
		//basic initialization
		this.hierarchicalAttributes = hierarchicalAttributes;
		trees = hierarchicalAttributes.getTrees();
		setUpTreeIndexMap();
		numRoots = trees.size();
	}
	
	private void walkTheTreesAndOrderTheNodes(){
		
	}
	
	private void setUpTreeIndexMap(){
		//just a backwards map
		for(Entry<Integer, AttributeNode> entry : trees.entrySet())
			treeIndexMap.put(entry.getValue(), entry.getKey());
	}
	
	@Override
	public List<List<Integer>> getCombinations(int n) {
		//get all combinations up to size n
		List<List<Integer>> combinations = new ArrayList<List<Integer>>();
		for(int i = 1; i <= n; i++)
			combinations.addAll(getCombinationsOfSize(i));
		return combinations;
	}
	
	private List<List<Integer>> getCombinationsOfSize(int k) {
		List<List<Integer>> combinations = new ArrayList<List<Integer>>();
		//AttributeNode[] kTokenPlaces = initializeKTokens(k);
		//while(true){
			//combinations.add(convertNodesToIndices(kTokenPlaces));
			//kTokenPlaces = updateTokenPlaces(kTokenPlaces);
			//if we get null back, it means there are no more combinations
			//if(kTokenPlaces == null) break;
		//}
		return combinations;
	}

	@Override
	public List<List<Integer>> getCombinationsUpToSize(int n, int k) {
		List<List<Integer>> combinations = new ArrayList<List<Integer>>();
		for(int i = 1; i <= k; i++)
			combinations.addAll(getCombinationsOfSize(i));
		return combinations;
	}
	

}
